﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FantastPlatform.Framework;
using FantastPlatform.Framework.Core;
using FantastPlatform.Framework.Model;
using FantastPlatform.Decision.IService;
using FantastPlatform.Decision.IModel;
using FantastPlatform.Decision.Model;

namespace FantastPlatform.Decision.UI.Service
{
    public partial class CommentsViewService : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoginEmployee = Session["User"] as FantastPlatform.Framework.Model.Employee;
            ICommentsService commentsService = ServiceFactory.CreateService<ICommentsService>();
            Condition enableCondition = new Condition() { Field = "Enable", Type = typeof(bool).FullName, Value1 = true };
            IMaintainStabilityService maintainStabilityService = ServiceFactory.CreateService<IMaintainStabilityService>();
            ConditionGroup group = new ConditionGroup();
            group.Conditions.Add(enableCondition);
            int totalCount = 0;
            switch (Action)
            {               
                case "Get":

                    IComments comments = commentsService.Get(Id);
                    object objComments = (new
                                     {                                         
                                         Name = comments.Name,
                                         Content = comments.Content
                                     });
                    ReturnObj(objComments);
                    break;
            
                case "GetCommentsByMaintainStability":
                    IMaintainStability maintainStability = maintainStabilityService.Get(Id);
                    object[] objList = (from o in maintainStability.Comments
                               select new
                               {
                                   Id = o.Id,
                                   Content = o.Content,
                                   ReplyDate = o.CreateDate.ToString(),
                                   PoliceMan = o.Person.Name
                               }).ToArray();
                    ReturnList(maintainStability.Comments.Count, objList);
                    break;
                case "GetCommentsByImportantCaseId":
                    IImportantCaseService importantCaseService = ServiceFactory.CreateService<IImportantCaseService>();
                    IImportantCase importantCase = importantCaseService.Get(Id);
                    object[] objList2 = (from o in importantCase.Comments                                         
                                        select new
                                        {
                                            Id = o.Id,
                                            Content = o.Content,
                                            ReplyDate = o.CreateDate.ToString(),
                                            PoliceMan = o.Person.Name
                                        }).ToArray();
                    ReturnList(importantCase.Comments.Count, objList2);
                    break;
            }
        }
        
    }
}